<template>
	<view>
		<view class="top">
			<view class="tit">
				余额提现 ￥{{this.data.momeny}}
			</view>
		</view>
		<view class="wx">
			<view class="box">
				到微信零钱
			</view>
		</view>
		<div class="wx">
			<el-input :min="100" v-model="number" @input='onchange' type="number" @change='panduan' :clearable='true'
				placeholder="输入金额(¥)最少为5"></el-input>
		</div>
		<view class="chong" @click="huan">
			<span>确认提现</span>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				number: '',
				data: []
			};
		},
		onLoad() {
			this.getdata()
		},
		methods: {
			getdata() {
				this.$api.getpsxintegral().then(res => {
					this.data = res.data[0]
					console.log(this.data);
				})
			},
			panduan() {
				if (this.number < 5) {
					uni.showToast({
						title: '提现最少为5哦~	',
						icon: 'none'
					})
					this.number = ''
				}
			},
			huan() {
				this.onchange()
				if (this.number == '') {
					uni.showToast({
						title: '请填写提现数额	',
						icon: 'none'
					})
				} else {
					let data = {
						id: this.data.id,
						momeny: Number(this.data.momeny) - Number(this.number)
					}
					this.$api.putpsxintegral(data).then(res => {
						console.log(res);
					})
					// this.number = ''
					console.log(1);
					uni.showToast({
						title: '充值成功	',
						icon: 'none'
					})
					this.$api.addpsxdetil({
						detil: "-"+this.number,
						code: 0 //0是减去
					}).then(res => {
						console.log(res);
						this.number = ''
						this.getdata()
					})
				}
			},
			onchange() {
				console.log(this.number);
				if (this.number > Number(this.data.momeny)) {
					uni.showToast({
						title: '您并没有那么多零钱哦~	',
						icon: 'none'
					})
					this.number = ''
				}

			},
		}
	}
</script>

<style lang="scss" scoped>
	.top {
		width: 750rpx;
		height: 218rpx;
		background-color: #fafafa;
		box-shadow: 0rpx 0rpx 15rpx 0rpx rgba(34, 24, 21, 0.15);
		border: solid 1rpx #d7d7d7;
		display: flex;
		justify-content: center;
		align-items: center;

		.tit {
			// width: 158rpx;
			height: 38rpx;
			font-family: YouYuan;
			font-size: 40rpx;
			font-weight: normal;
			font-stretch: normal;
			letter-spacing: 0rpx;
			color: #171717;
		}
	}

	.wx {
		width: 750rpx;
		height: 88rpx;
		background-color: #fafafa;
		box-shadow: 0rpx 0rpx 15rpx 0rpx rgba(34, 24, 21, 0.15);
		border: solid 1rpx #d7d7d7;
		margin: 40rpx 0;
		display: flex;
		align-items: center;

		.box {
			margin-left: 40rpx;
			// width: 126rpx;
			height: 31rpx;
			font-family: YouYuan;
			font-size: 32rpx;
			font-weight: normal;
			font-stretch: normal;
			letter-spacing: 0rpx;
			color: #171717;
		}
	}

	.chong {
		width: 710rpx;
		height: 88rpx;
		background-color: #8fc31f;
		border: solid 1rpx #bababa;
		margin: auto;
		display: flex;
		justify-content: center;
		align-items: center;

		span {
			// width: 127rpx;
			height: 31rpx;
			font-family: YouYuan;
			font-size: 32rpx;
			font-weight: normal;
			font-stretch: normal;
			letter-spacing: 0rpx;
			color: #fafafa;
		}
	}
</style>
